

import nw from "nw-lafjs";
import {fail, ok} from "@/utils/responseUtil";

export default async function (ctx: FunctionContext) {
  let body = ctx.body
  let userId = ctx.user.admin

  let user = await nw.db.findById({
    dbName:"user",
    id:userId
  })
  if (nw.util.isNull(user)){
    return fail("用户不存在")
  }

  let dataJson = {
    sex:body.sex ||user.sex,
    photoUrl:body.photoUrl||user.photoUrl,
    nickName:body.nickName||user.nickName
  }

  let num = await nw.db.update({
    dbName:"user",
    whereJson:{_id:userId},
    dataJson:dataJson
  })
  if (num<0){
    return fail("更新失败")
  }
  return ok("更新成功")
}
